/* 
 * File:   JUuid.cpp
 * Author: johnneyshi
 * 
 * Created on 2013年1月6日, 上午11:41
 */

#include "JUuid.h"
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <boost/lexical_cast.hpp>
#include "JDefine.h"

JUuid::JUuid()
{
    
}

JUuid::~JUuid() {
}

std::string JUuid::ToString()
{
    using namespace boost::uuids;
    uuid u = random_generator()();
    return boost::lexical_cast<std::string>(u);
   //return std::string(u.data);
}

bool JUuid::operator ==(const JUuid& _uuid)
{
    if(this->strUuid == _uuid.strUuid)
    {
        return true;
    }
    return false;
}

int JUuid::Serialize(JInOutPut& strea, int& allSize)
{
    int classSize = 0,selfSize = 0;
    JSerialize::PutInt(strea,classSize,selfSize);
    JSerialize::Serialize(strea,this->strUuid,classSize);
    
    selfSize += classSize;
    JSerialize::Verify(strea,classSize,-1*selfSize);
    allSize += selfSize;
    return selfSize;
}

int JUuid::ReSerialize(JInOutPut& strea)
{
    int classSize = JSerialize::GetInt(strea,SIZEOF_INT);
    this->strUuid = JSerialize::ReSerializeString(strea);
    return classSize;
}

std::string JUuid::Generate()
{
    return this->strUuid = ToString();
}

std::string JUuid::Get()
{
    return this->strUuid;
}